//
//  YZLHomePageViewController.m
//  Car
//
//  Created by dllo on 15/10/28.
//  Copyright © 2015年 岳明. All rights reserved.
//

#import "YZLHomePageViewController.h"
#import "Macro.h"

@interface YZLHomePageViewController ()

@property (nonatomic, strong) UICollectionView *collectionVierw; /**< 内容 */
@property (nonatomic, strong) UIScrollView *scrollView; /**< 标签 */
@property (nonatomic, strong) UIButton *button; /**< 下拉控件 */
@property (nonatomic, strong) NSArray *tagArray; /**< 标签数组 */
@property (nonatomic, strong) NSArray *tagShowArray; /**< 显示的标签数组 */
@property (nonatomic, strong) NSArray *tagHideArray; /**< 隐藏的标签数组 */

@end

@implementation YZLHomePageViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"tagArray.plist"];
    /* 判断文件是否存在 */
    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
        /* 存在则导出 */
        self.tagArray = [NSArray arrayWithContentsOfFile:path];
    } else {
        /* 不存在则写入 */
        self.tagArray = @[@{
                            @"最新": @{
                                  @"title":@"最新",
                                  @"frist":@"a",
                                  @"last":@"getNewsList",
                                  @"type":@"1"
                                  },
                             @"新闻": @{
                                  @"title":@"新闻",
                                  @"frist":@"a",
                                  @"last":@"getNewsList",
                                  @"type":@"2"
                                  },
                             @"测评": @{
                                  @"title":@"测评",
                                  @"frist":@"a",
                                  @"last":@"getNewsList",
                                  @"type":@"3"
                                  },
                             @"导购": @{
                                  @"title":@"导购",
                                  @"frist":@"a",
                                  @"last":@"getNewsList",
                                  @"type":@"4"
                                  },
                             @"油价变动": @{
                                  @"title":@"油价变动",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"1"
                                  },
                             @"车辆召回": @{
                                  @"title":@"车辆召回",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"2"
                                  },
                             @"新车上市": @{
                                  @"title":@"新车上市",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"3"
                                  },
                             @"新技术": @{
                                  @"title":@"新技术",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"4"
                                  },
                             @"新能源车": @{
                                  @"title":@"新能源车",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"6"
                                  },
                             @"新车谍照": @{
                                  @"title":@"新车谍照",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"8"
                                  },
                             @"多车对比": @{
                                  @"title":@"多车对比",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"20"
                                  },
                             @"对比选车": @{
                                  @"title":@"对比选车",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"28"
                                  },
                             @"激情赛车": @{
                                  @"title":@"激情赛车",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"33"
                                  },
                             @"汽车音响": @{
                                  @"title":@"汽车音响",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"985"
                                  },
                             @"奇闻车市": @{
                                  @"title":@"奇闻车市",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"1540"
                                  },
                             @"概念车": @{
                                  @"title":@"概念车",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"18534"
                                  },
                             @"SUV对比": @{
                                  @"title":@"SUV对比",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"76392"
                                  },
                             @"购车技巧": @{
                                  @"title":@"购车技巧",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"76395"
                                  },
                             @"改装升级": @{
                                  @"title":@"改装升级",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"83757"
                                  },
                             @"视频": @{
                                  @"title":@"视频",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"144998"
                                  },
                             @"旅行游记": @{
                                  @"title":@"旅行游记",
                                  @"frist":@"mi",
                                  @"last":@"getdingyue",
                                  @"type":@"154980"
                                  },
                            @"sum":@"5"
                              }];
        [self.tagArray writeToFile:path atomically:YES];
    }
}

- (void)createScrollView {
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, kWidth - kWidth / 8, 40)];
    [self.view addSubview:self.scrollView];
    self.scrollView.backgroundColor = [UIColor brownColor];
}

- (void)createButton {
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.button];
    self.button.backgroundColor = [UIColor purpleColor];
    self.button.frame = CGRectMake(kWidth - kWidth / 8, 64, kWidth / 8, 40);
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"XXXX";
    
    //取出文件中的显示的标签个数
    NSInteger tagShowNum = [[[self.tagArray lastObject] objectForKey:@"sum"] integerValue];
    
    //取出显示的数组内容
    NSMutableArray *mTagShowArr = [NSMutableArray array];
    for (int i = 0; i < tagShowNum; i++) {
        [mTagShowArr addObject:[self.tagArray objectAtIndex:i]];
    }
    self.tagShowArray = mTagShowArr;
    
    //取出隐藏的数组内容
    NSMutableArray *mTagHideArr = [NSMutableArray array];
    for (NSInteger i = tagShowNum; i < self.tagArray.count; i++) {
        [mTagHideArr addObject:[self.tagArray objectAtIndex:i]];
    }
    self.tagHideArray = mTagHideArr;
    
    
    [self createScrollView];
    [self createButton];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
